// pages/buy/buy.js
const app = getApp()
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isshow: false,
    isshop: false,
    havesp: 0,
    spnum: 1,
    panduan1: true,
    panduan2: false,
    ztcolo: "colorbor",
    allcolo: "cur",
    showimg: "",
    infor: [
      {
        name: "需使用4G飞享套餐。赠送12GB流量，2400分钟通话",
        price: "69.90",
        yunfei: "8",
        kucun: "10",
        xiaoliang: "29",
        num: "4455",
        movies: [
          '../../images/banner2.jpg',
          '../../images/banner1.jpg',
        ],
      }
    ],
    xiangqing: [
      {
        images: [
          '../../images/banner1.jpg',
          '../../images/banner1.jpg',
        ],
      },
    ],
    
  },
  //购买
  showjrshop: function () {
    this.setData({
      isshop: true
    })
  },
  addnum: function () {
  
    var spnum = this.data.spnum;
    spnum++;
   
    var money=this.data.data.min_price
    this.setData({
      spnum: spnum,
      price: money * spnum
    })
  },
  cannum: function () {
    var spnum = this.data.spnum;
    spnum--;
    if (spnum <= 0) {
      spnum = 1;
    }
 
    var money = this.data.data.min_price
    this.setData({
      spnum: spnum,
      price: money * spnum
    })
  },
  toloasesjo: function () {
    this.setData({
      isshop: false
    })
  },
  order:function(e){
    var that=this;
    var id = e.currentTarget.dataset.id;
    var num = that.data.spnum;
    app.navTo('../order/order?id='+id+'&num='+num)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: app.appUrl + '/goods/detail',
      data: {
        goodsid: options.id
      },
      success: function (res) {

        var article = res.data.data.content
        WxParse.wxParse('article', 'html', article, that, 5)
        that.setData({       
          data: res.data.data,
          price:res.data.data.min_price
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})